package controller

import (
	"Bluebell/common/resp"
	"Bluebell/logic"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

func CommunityHandler(context *gin.Context) {
	data, err := logic.GetCommunityList()
	if err != nil {
		zap.L().Error("logic.GetCommunityList failed", zap.Error(err))
		resp.ResponseError(context, resp.CodeServerBusy)
		return
	}
	resp.ResponseSuccess(context, data)
}

func CommunityDetailHandler(context *gin.Context) {
	idStr := context.Param("id")
	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		resp.ResponseError(context, resp.CodeInvalidParams)
		return
	}
	data, err := logic.GetCommunityDetail(uint64(id))
	if err != nil {
		zap.L().Error("logic.GetCommunityDetail failed", zap.Error(err))
		resp.ResponseError(context, resp.CodeServerBusy)
		return
	}
	resp.ResponseSuccess(context, data)
}
